package chapter19.file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Auther: Tx
 * @Date: 2022/7/20 21:24
 */
//文件拷贝
public class FileCopy {
    public static void main(String[] args) {
        String resPath = "e://tx_white.jpg";
        String desPath = "e://tx_white2.jpg";
        byte[] readData = new byte[10];
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        int readLen;
        try {

            fileInputStream = new FileInputStream(resPath);
            fileOutputStream = new FileOutputStream(desPath);
            //读取文件
            while ((readLen=fileInputStream.read(readData))!=-1){
                   fileOutputStream.write(readData,0,readLen);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
finally {
            try {
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
